<!--
	课程基础信息微维护
-->
<template>
<!-- 最外层当背景 start -->
<div class="box">
<!-- 里面这层限制大小内容位置 start -->
<div class="content">
	<el-form ref="formRef" :model="baseInfo" label-width="120px">
		<el-form-item label="课程名称">
			<el-input v-model="baseInfo.name"></el-input>
		</el-form-item>
		<el-form-item label="课程介绍">
			<el-input
				v-model="baseInfo.description"
				:rows="2"
				type="textarea"
				placeholder="请输入课程介绍"/>
		</el-form-item>
		<el-form-item label="课程大纲">
			<el-input
				v-model="baseInfo.syllabus"
				:rows="2"
				type="textarea"
				placeholder="请输入课程大纲"/>
		</el-form-item>
		<el-form-item>
			<el-button type="primary" @click="onSubmit">修改</el-button>
			<el-button>取消</el-button>
		</el-form-item>
	</el-form>
</div>
<!-- 里面这层限制大小内容位置 end -->
</div>
<!-- 最外层当背景 end -->
</template>

<script>
import {mapState} from "vuex"
import ipconfig from "@/utils/ipconfig";
import axios from "@/plugins/axios";
import {ElMessage} from "element-plus";

export default {
	name: "CourseBaseInfo",
	data(){
		return {
			/**
			 * 教师登录数据
			 */
			teacherInfoData:this.$store.state.teacherInfoData,
			/**
			 * 保存编辑的信息
			 */
			baseInfo:{},
		}
	},
	computed:{
		...mapState({
			thisEditCourse:state=> state.teacherInfoData.thisEditCourse,
		}),
	},
	methods:{
		onSubmit(){
			axios.post(ipconfig.address+"/course/updateCourse",{
				...this.baseInfo
			}).then((response)=>{
				if(response.data.code==200){
					axios.get(ipconfig.address+"/course/courseItem/"+this.baseInfo.id).then((response)=>{
						if(response.data.code==200){
							ElMessage.success(response.data.message);
							this.teacherInfoData.thisEditCourse=response.data.data;
						}else{
						    ElMessage.warning(response.data.message);
						}
					}).catch((error)=>{
					    console.log(error);
					});

				}else{
				    ElMessage.warning(response.data.message);
				}
			}).catch((error)=>{
			    console.log(error);
			});
			console.log(this.baseInfo);
		}
	},
	mounted() {
		this.baseInfo={
			id: this.thisEditCourse.id,
			name: this.thisEditCourse.name+"",
			description: this.thisEditCourse.description+"",
			syllabus: this.thisEditCourse.syllabus+"",
		}
	},
}
</script>

<style lang="scss" scoped>
.box{
	width: 100%;
	background: #ffffff;

	.content{
		padding: 40px ;
	}

}
</style>